<?php

namespace App\Models;

use Slowlyo\OwlAdmin\Models\BaseModel as Model;
use Slowlyo\OwlAdmin\Models\AdminUser;

/**
 * IDC机房管理
 */
class Idcnode extends Model
{
	protected $table = 'idcnode';

	protected static function boot()
	{
		parent::boot();

		static::creating(function ($model) {
			$model->created_at = date('Y-m-d H:i:s');
			$model->updated_at = date('Y-m-d H:i:s');
			$model->operator_uid = admin_user()->id;
			$model->editor_uid = admin_user()->id;
		});

		static::updating(function ($model) {
			$model->updated_at = date('Y-m-d H:i:s');
			$model->editor_uid = admin_user()->id;
		});
	}

    /**
     * 获取操作人信息
     */
    public function operator()
    {
        return $this->belongsTo(AdminUser::class, 'operator_uid');
    }

    protected function getIdcBelongAttribute($value)
    {
        return $value ? explode(',', $value) : [];
    }

    protected function setIdcBelongAttribute($value)
    {
        $this->attributes['idc_belong'] = is_array($value) ? implode(',', $value) : $value;
    }
}